class Page2 extends egret.Sprite {
	private building: egret.Bitmap;
	private blink: egret.Bitmap;
	private arr_pic;
	public constructor() {
		super();
		this.initial();
	}
	public initial() {
		var bg = new egret.Bitmap(RES.getRes("bg2_png"));
		this.addChild(bg);

		this.building = new egret.Bitmap(RES.getRes("page2pic_png"));
		this.addChild(this.building);

		this.blink = new egret.Bitmap(RES.getRes("page2blink_png"));
		this.addChild(this.blink);


		this.arr_pic = new Array();
		for (var z = 1; z <= 10; z++) {
			var pic = new egret.Bitmap(RES.getRes("page2pic" + z + "_png"));
			this.addChild(pic);
			switch (z) {
				case 1: pic.x = 248; pic.y = 205; break;
				case 2: pic.x = 473; pic.y = 254; break;
				case 3: pic.x = 120; pic.y = 313; break;
				case 4: pic.x = 181; pic.y = 402; break;
				case 5: pic.x = 297; pic.y = 437; break;
				case 6: pic.x = 198; pic.y = 530; break;
				case 7: pic.x = 285; pic.y = 580; break;
				case 8: pic.x = 122; pic.y = 630; break;
				case 9: pic.x = 327; pic.y = 680; break;
				case 10: pic.x = 206; pic.y = 730; break;
			}
			this.arr_pic.push(pic);
		}
		this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.TB, this);

	}
	private TB(e: TouchEvent) {
		this.touchEnabled = false;
		GoEvent.msg.dispatchEvent(new GoEvent("ChangePage", "3"));
	}
	public End() {
		egret.Tween.get(this).to({ alpha: 0 }, 600, egret.Ease.cubicOut);
	}

	public Show() {
		var This = this;
		// this.touchEnabled=true;
		setTimeout(function () {
			This.touchEnabled = true;
		}, 3300)

		var balaThis = this;
		this.alpha = 0;
		egret.Tween.get(this).to({ alpha: 1 }, 700, egret.Ease.cubicOut);

		this.building.alpha = 0;
		this.building.y = 711 + 40;
		egret.Tween.get(this.building).wait(500).to({ alpha: 1, y: 711 }, 900, egret.Ease.cubicOut);


		this.blink.alpha = 0;
		this.blink.y = 711;
		setTimeout(function () {
			egret.Tween.get(balaThis.blink, { loop: true }).to({ alpha: 1 }, 1000, egret.Ease.cubicOut).to({ alpha: 0 }, 1000, egret.Ease.cubicOut);
		}, 1500)

		for (var z = 0; z < this.arr_pic.length; z++) {
			this.arr_pic[z].alpha = 0;
			if (z < 5) {
				if (z == 1) {
					this.arr_pic[z].x =520;
					egret.Tween.get(this.arr_pic[z]).wait(1000 + z * 200).to({ alpha: 1, x: 473 }, 800, egret.Ease.cubicOut);
				}
				else {
					this.arr_pic[z].y -= 40;
					egret.Tween.get(this.arr_pic[z]).wait(1000 + z * 200).to({ alpha: 1, y: this.arr_pic[z].y + 40 }, 800, egret.Ease.cubicOut);
				}
			}
			else {
				this.arr_pic[z].x += (z % 2) * 60 - 30;
				egret.Tween.get(this.arr_pic[z]).wait(1000 + z * 200).to({ alpha: 1, x: this.arr_pic[z].x - ((z % 2) * 60 - 30) }, 800, egret.Ease.cubicOut);
			}
		}
	}
}